<template>
  <div class="app-container">
    <!-- <el-form :model="queryParams" ref="queryRef" :inline="true">
            <el-form-item label="下单标准编码">
                <el-input v-model="queryParams.orderNum" placeholder="下单标准编码" clearable style="width: 200px"
                    @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="机器类型">
                <el-select v-model="queryParams.machinetype" class="m-2" placeholder="请选择机器类型" style="width: 200px;">
                    <el-option v-for="item in mes_paperproduction_machine" :key="item.label" :label="item.label"
                        :value="item.value" />
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
                <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form> -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="Plus" @click="handleAdd"
          >新增</el-button
        >
      </el-col>
      <!-- <right-toolbar
        v-model:showSearch="showSearch"
        @queryTable="getList"
      ></right-toolbar> -->
    </el-row>
    <el-table v-loading="loading" border :data="supplierList">
      <el-table-column label="序号" width="60" type="index" align="center">
      </el-table-column>
      <el-table-column label="下单标准编码" align="center" prop="orderNum">
        <template v-slot="{ row }">
          <el-button type="primary" @click="handleView(row)" link>{{
            row.orderNum
          }}</el-button>
        </template>
      </el-table-column>
      <el-table-column label="印刷方式" align="center" prop="printType">
        <template #default="scope">
          <dict-tag :options="mes_paper_package" :value="scope.row.printType" />
        </template>
      </el-table-column>
      <el-table-column label="版材尺寸" align="center" prop="sheetSize">
        <template #default="scope">
          <dict-tag
            :options="ems_machine_info_size"
            :value="scope.row.sheetSize"
          />
        </template>
      </el-table-column>
      <el-table-column label="车间" align="center" prop="workshopName" />
      <el-table-column label="备注" align="center" prop="remark">
      </el-table-column>
      <el-table-column
        label="操作"
        fixed="right"
        align="center"
        width="150"
        class-name="small-padding fixed-width"
      >
        <template #default="scope">
          <el-tooltip content="编辑" placement="top">
            <el-button
              link
              type="primary"
              icon="Edit"
              @click="handleEdit(scope.row)"
            ></el-button>
          </el-tooltip>
          <el-tooltip content="删除" placement="top">
            <el-button
              link
              type="primary"
              icon="Delete"
              @click="handleDle(scope.row)"
            ></el-button>
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      style="margin-top: 0; padding-top: 0"
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>
<script setup name="customer">
import {
  paperOrderGetlist,
  paperOrderDeleteById,
  getCoefficient,
} from "@/api/basicInfo/PaperProduction.js";
const { proxy } = getCurrentInstance();
const { mes_paper_package, ems_machine_info_size } = proxy.useDict(
  "mes_paper_package",
  "ems_machine_info_size"
);
import { ElMessage, ElMessageBox } from "element-plus";
const router = useRouter();
const supplierList = ref([]);
const loading = ref(false);
const total = ref(0);
const formValue = ref({});
const showSearch = ref(true);
const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    code: null,
    name: null,
  },
  rules: {
    code: [{ required: true, message: "客户编码不能为空", trigger: "blur" }],
    name: [{ required: true, message: "客户名称不能为空", trigger: "blur" }],
  },
});
const { queryParams, form, rules } = toRefs(data);

// 新增
const handleAdd = () => {
  router.push("/basicInfo/paperProduction/details");
};
// 复制新增
const handleCopy = (row) => {
  getPaperProduction(row.id)
    .then((response) => {
      const data = response.data || {};
      formValue.value = { ...data };
      formValue.value.mesPlaceorderMachineinfoList =
        response.data.mesPlaceorderMachineinfoList;
      formValue.value.mesPlaceorderSetupinfoList =
        response.data.mesPlaceorderSetupinfoList;
      console.log("formValue1", formValue.value);
    })
    .then((success) => {
      ElMessage({
        message: "复制新增成功",
        type: "success",
      });
      formValue.value.status = 1;
      formValue.value.issubmit = 0;
      addPaperProduction(formValue.value).then((response2) => {
        getList();
      });
    });
};
const handleEdit = (row) => {
  router.push({
    path: "/basicInfo/paperProduction/details",
    query: {
      id: row.id,
      status: row.status,
      code: row.orderNum,
    },
  });
};
// 查看
const handleView = (row) => {
  router.push({
    path: "/basicInfo/paperProduction/details",
    query: {
      id: row.id,
      status: row.status,
      code: row.orderNum,
      readonly: true,
    },
  });
};
//停用启用

const handleServe = (row) => {
  if (row.status === 1) {
    searchStatus({ machinetype: row.machinetype }).then((response) => {
      console.log("responseStatus", response);
      if (response.data !== 0) {
        return ElMessage({
          message: "同一个机器类型 只能启用一台",
          type: "warning",
        });
      } else {
        const state = row.status === 0 ? "1" : "0";
        const stateText = row.status === 0 ? "停用" : "启用";
        ElMessageBox.confirm(`确定要 ${stateText} 吗?`, "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then(() => {
          // 用户点击了确定按钮
          row.status = state;
          row.issubmit = 1;
          updatestatusProduction({ ...row }).then((response) => {
            if (response.code === 200) {
              ElMessage({
                message: `${stateText}成功`,
                type: "success",
              });
              getList();
            }
          });
        });
      }
    });
  } else {
    const state = row.status === 0 ? "1" : "0";
    const stateText = row.status === 0 ? "停用" : "启用";
    ElMessageBox.confirm(`确定要 ${stateText} 吗?`, "提示", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning",
    }).then(() => {
      // 用户点击了确定按钮
      row.status = state;
      row.issubmit = 1;
      updatestatusProduction({ ...row }).then((response) => {
        if (response.code === 200) {
          ElMessage({
            message: `${stateText}成功`,
            type: "success",
          });
          getList();
        }
      });
    });
  }
};

//删除
const handleDle = (row) => {
  ElMessageBox.confirm("确定要删除改数据吗?", "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(() => {
      // 用户点击了确定按钮
      paperOrderDeleteById({ id: row.id }).then((response) => {
        if (response.code === 200) {
          ElMessage({
            message: "删除成功",
            type: "success",
          });
          getList();
        }
      });
    })
    .catch(() => {
      //取消
    });
};
function getList() {
  loading.value = true;
  paperOrderGetlist(queryParams.value)
    .then((response) => {
      supplierList.value = response.data;
      total.value = response.total;
      loading.value = false;
    })
    .catch((err) => {
      loading.value = false;
    });
}
/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}
/** 重置按钮操作 */
function resetQuery() {
  queryParams.value.orderNum = null;
  queryParams.value.machinetype = null;
  handleQuery();
}

getList();
</script>
 